<%-- 
    Document   : LoginStatus
    Created on : Sep 2, 2011, 1:59:02 AM
    Author     : James
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList, BusinessLogic.Constants, EntityState.CustomerState" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>FoodSage - Singapore online food court</title>
        <link rel="stylesheet" href="../customer/main_style_sheet.css" />
        <script type='text/javascript' src='../jQuery/jquery-1.6.1.min.js'></script>
        <script type="text/javascript" src="../customer/script/Utilities.js"></script>
        <script type='text/javascript'>
            function resendActivation(email)
            {
                $.ajax({
                    type: "POST",
                    url: "ResendActivation",
                    data: {
                        username: $("username").val(),
                        email: email
                    },
                    success: function(){
                        $("content").html("<p class='white' align='middle'>We have re-sent an activation email. Please proceed to activate your account.</p>");
                    },
                    dataType: "text"
                });
            }
            
            $('#main_login_form').submit(function() {
                if ($('#username').val() == "") {
                    alert("Please enter the Username.");
                    focusIt("username");
                    return false;

                } else if ($('#password').val() == "") {
                    alert("Please enter the Password.");
                    focusIt("password");
                    return false;
                    
                } 
                return true;
            });
        </script>
    </head>
    <body>
        <div id="wrapper">
            <h1>FoodSage</h1>
            <div id="nav">
                <a href="Redirect?page=CourseRegistration">Course Registration</a>
                <a href="Redirect?page=search&target=ad">About Us</a>
                <a href="Redirect?page=about_us">Our Languages</a>
                <a href="Redirect?page=contact">Support</a>
            </div>
            <div id="body">
                <div id="body-top">
                    <div id="body-bot">
                        <div id="welcome">
                            <img src="../customer/images/books2.jpg" width="276" height="238" alt="Pic 1" />
                        </div>
                            <%
                                ArrayList data = (ArrayList) request.getAttribute("data");
                                int result = ((Integer) data.get(0)).intValue();
                                String URL   = request.getParameter("currentURL");
                                
                                if (result == Constants.STATUS_WRONG_PASSWORD) {
                            %>
                            <div id="login_panel">
                                <p align="middle"><font color="#FF0000">Wrong Username or Password.</font></p>
                                <form action="https://localhost:8181/portal/public/LoginStatus" id="main_login_form" name="login_form" method="POST">
                                    <input type="hidden" id="currentURL" name="currentURL" value ="<%= URL %>"/>
                                    <table width="260">
                                        <tr>
                                            <td width="75" align="right"><span style="font-size:15px">Username:</span></td>
                                            <td><input type="text" id="username" name="username" size="20" value=""/></td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td><span style='font-size:10px;color:#FFFFFF;'><a href="http://localhost:8181/portal/public/Forgot?target=username">(Forgot your Username?)</a></span></td>
                                        </tr>
                                        <tr>
                                            <td align="right"><span style="font-size:15px">Password:</span></td>
                                            <td><input type="password" id="password" name="password" size="20" value=""/></td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td><span style='font-size:10px;color:#FFFFFF;'><a href="http://localhost:8181/portal/public/Forgot?target=password">(Forgot your Password?)</a></span></td>
                                        </tr>
                                    </table>
                                    <p align="middle"><input type="submit" value="Sign in" /></p>
                                </form>
                                <hr>
                                <p class="white" align="middle">Don't have a Lingua123 ID?<br/><br/>
                                    <input type="button" align="middle" value="Create New Account" onclick="window.open('http://localhost:8181/portal/public/AccountRegistration');" />
                                </p>
                            </div>
                            <div id="content"></div>
                            <%
                                } else if (result == Constants.STATUS_USER_INACTIVATED) {
                                    String username = (String) data.get(1);
                            %>
                            <div id="content">
                                <input type="hidden" id="username" name="username" value="<%= username %>">
                                <p class="white" align="middle">You are not allowed to login at the moment.<br/>
                                    We have sent an activation email to your Email account. <br/>
                                    Please proceed to activate your account first.<br/>
                                    If you want us to send the activation email again, please click <span style="font-size:15px;color:#383838 ;" onmouseover="this.style.cursor='pointer'" onclick="resendActivation();"><u>here</u></span>. <br/>
                                </p>
                            </div>
                            <%
                                } else {
                                    CustomerState us = (CustomerState) session.getAttribute("user");
                            %>
                            <div id="content">
                                <p class="white" align="middle">Welcome, <%= us.getUsername() %><br/>
                                    Click <a href="<%= URL %>">here</a> to return to where you were previously. <br/>
                                    Click <a href="http://localhost:8181/portal/public/">here</a> to return to the Homepage.<br/>
                                </p>
                            </div>
                            <script type="text/javascript">
                                window.location.replace("<%= URL %>");
                            </script>
                            <%
                                }
                            %>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>